package cn.tedu.ivos.base.util;

import java.security.SecureRandom;

/*密码工具类，生成随机密码*/
public class PasswordUtil {
    private static final String ALL_CHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final SecureRandom random=new SecureRandom();

    /*创建生成指定位随机密码串的静态方法*/
    public static String generateRandomPassword(int length){
        if (length<5) throw new RuntimeException("密码长度不能小于5");
        StringBuilder password =new StringBuilder();
        for (int i =0;i<length;i++){
            int index =random.nextInt(ALL_CHAR.length());
            char randomChar = ALL_CHAR.charAt(index);
            password.append(randomChar);
        }
        return password.toString();
    }
}
